package com.sup.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sup.model.Production;
import com.sup.repository.ProductionRepository;

@Service
public class ProductionService {
	@Autowired
	ProductionRepository productionRepository;
	
	@Transactional
	public void saveProduction(Production production){
		productionRepository.save(production);
	}
	
	@Transactional
	public void removeProduction(Long id){
		productionRepository.delete(id);
	}
	
	public Production findProductionById(Long id){
		return productionRepository.findOne(id);
	}
	
	public Production findProductionByName(String name){
		return productionRepository.findProductionByName(name);
	}
	
	public Page<Production> getProductionPage(int pageIndx,int size){
		Page<Production> page=productionRepository.findProductions(new PageRequest(pageIndx, size, Direction.ASC, "id"));
		return page;
	}
	
	public List<Production> findAll(){
		return productionRepository.findAll();
	}
}
